<template>
  <div style="margin-top:40px">
    <Add />
    <!-- 表格 -->
    <div class="table">
      <el-table :data="list" stripe @selection-change="handleSelectionChange" :cell-style="{ 'text-align': 'center' }"
        border>
        <el-table-column align="center" prop="id" label="编号"></el-table-column>
        <el-table-column align="center" prop="name" label="类型名称">
        </el-table-column>
        <el-table-column align="center" prop="attributeCount" label="属性数量">
        </el-table-column>
        <el-table-column align="center" prop="paramCount" label="参数数量">
        </el-table-column>
        <el-table-column align="center" width="180px" prop="createTime" label="设置">
          <template #default="scope">
            <div style="display: flex;justify-content: space-between; x">
              <div>
                <el-button size="small" style="margin-right:10px" @click="nextStep(scope.row.id)">查看下级</el-button>
              </div>
              <div>
                <el-button size="small">转移商品</el-button>
              </div>
            </div>
          </template>
        </el-table-column>
        <el-table-column align="center" prop="status" label="操作" width="140px">
          <template #default="scope">
            <div style="display: flex;justify-content: space-between; ">
              <div>
                <el-button type="default" @click="edit(scope.row.id)" size="small" style="margin-right:10px">编辑
                </el-button>
              </div>
              <div>
                <el-button type="danger" size="small">删除</el-button>
              </div>
            </div>
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页 -->
      <div class="pagination">
        <el-pagination :page-sizes="[5, 10, 50, 100]" :default-page-size="5"
          layout="total, sizes, prev, pager, next, jumper" :total="paginateData.total" background
          @size-change="handleSizeChange" @current-change="handleCurrentChange" />
      </div>
    </div>
  </div>
</template>
  
<script setup lang='ts'>
import Add from './components/add.vue'
import { useTable } from '@/hook/table';
import { nextTick, reactive, ref, watch } from 'vue';
import * as http from '@/request/api'
import { useRouter, useRoute } from 'vue-router'

const router = useRouter()
const route = useRoute()
let params = reactive<IProduct>({
  pageSize: 5,
})
let { list, paginateData, handleSizeChange, getData, handleCurrentChange } = useTable(http.product.ProductAttributeCategoryList, params)

function handleSelectionChange() { }

// 查看下级
async function nextStep(id: number) {
  await router.push(`/pms/productCate?parentId=${id}`)
  getData()
}

// 编辑
function edit(id: number) {
  router.push(`/pms/updateProductCate?id=${id}`)
}
</script>
  
<style>
.pagination {
  height: 40px;
  margin: 10px;
  padding-bottom: 10px;
  float: right;
}

.el-table__row {
  height: 60px;
}
</style>